package com.whut.controller;

import com.whut.service.StatisticService;
import com.whut.v_model.ProblemCollectDetail;
import com.whut.v_model.RiskWarning;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/statistic")
public class StatisticController {
    @Resource
    private StatisticService statisticService;

    @ResponseBody
    @PostMapping("/unitRanking")
    public Object getUnitRanking(String startTime, String endTime, String unitType, int curPage, int pageSize) {
        if (unitType.equals("1")) {
            return statisticService.getAllUnitRanking(startTime, endTime, curPage, pageSize);
        } else {
            return statisticService.getUnitRanking(startTime, endTime, unitType, curPage, pageSize);
        }
    }

    @ResponseBody
    @PostMapping("/getTaskByContractId")
    public Object getTaskByContractId(String contractId) {
        return statisticService.getTaskByContractId(contractId);
    }

    @ResponseBody
    @PostMapping("/getProjectByTaskId")
    public Object getProjectByTaskId(String taskId, String startTime, String endTime,String unit) {
        if(unit.equals("one"))
        {
           return statisticService.getProjectOnlyByTaskId(taskId,startTime,endTime);
        }else if(unit.indexOf("cluster")!=-1)
        {
            return statisticService.getProjectForFuzzyCluster(taskId,startTime,endTime,unit.substring(unit.length()-1));
        }
        else {
            return statisticService.getProjectByTaskId(taskId, startTime, endTime,unit);
        }
    }

    @ResponseBody
    @PostMapping("/getAllUnitInfo")
    public Object getAllUnitInfo(String contractId,String startTime,String endTime) {
        return statisticService.getAllUnitInfo(contractId,startTime,endTime);
    }

    @ResponseBody
    @PostMapping("/getProblemCollectInfo")
    public Object getProblemCollectInfo(String checkId){
        return statisticService.getProblemCollectInfo(checkId);
    }

    @ResponseBody
    @PostMapping("/getStatisticRiskPointInfo")
    public Object getStatisticRiskPointInfo(String checkId,String system){
        return statisticService.getStatisticRiskPointInfo(checkId,system);
    }

    @ResponseBody
    @PostMapping("/problemNumSearch1")
    public Object getProblemNumSearch1(String checkId,String system){
        return statisticService.getProblemNumSearch1(checkId,system);
    }

    @ResponseBody
    @PostMapping("/getRiskPointStatisticInfo")
    public Object getRiskPointStatisticInfo(String checkId,String system){
        return statisticService.getRiskPointStatisticInfo(checkId,system);
    }


    /**
     * 根据委托方Id 与 搜索类型来搜索工程的统计信息
     * @author fuzhenjie
     * @date 19.7.27 16:49
     * @param contractId int 合同ID
     * @param type int 搜索种类 0 搜索周期；1 月；2 季；3 年
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/projectScoreTendency")
    public Object getProjectScoreTendency(int contractId,int type){
        return statisticService.getProjectScoreTendency(contractId,type);
    }

    /**
    * 根据确定的检查ID查找这次检查中第四级别的统计信息（APP使用）
    * @author fuzhenjie
    * @date 19.7.27 17:01
    * @param checkId int 检查ID
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/checkFourthStatistics")
    public Object getCheckFourthStatistics(int checkId){
        return statisticService.getCheckFourthStatistics(checkId);
    }

    /**
    * 根据确定的合同ID 以及参建单位类型 以及搜索时间类型 返回 参建单位排序评分统计信息（APP使用）
    * @author fuzhenjie
    * @date 19.7.27 21:13
    * @param contractId int 委托方ID/合同ID
    * @param unitType int 参建单位类型 0：sgUnit施工单位  1：jlUnit监理单位  2：jsUnit建设单位
    * @param timeType int 搜索时间类型 0：null 1:本月与上月 2：本季度与上季度  3：今年与去年
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/unitPointRankByContract")
    public Object getUnitPointRankByContract(int contractId,int unitType,int timeType){
        return statisticService.getUnitPointRank(contractId,unitType,timeType);
    }

    /**
     * 通过周期ID （taskId） 得到已经结束的cct列表
     * @author fuzhenjie
     * @date 19.7.28 21:40
     * @param taskId int 周期ID
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/finishedCheckList")
    public Object getFinishedCheckList(int taskId,@Nullable String st,@Nullable String et){
        return statisticService.getFinishedCheckByTaskId(taskId,st,et);
    }

/*LYL*/

    /**
    * 通过checkId数组 和 体系Id 来获取项目的分数统计信息（包括jsUnit,jl,sg）
    * @author liyvanliang
    * @date 2019/7/30 16:52
    * @param checkId String 形如 "[1,2,3]"
    * @param number int
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getProjectPiont")
    public Object getProjectPiont(String checkId,int number){
        return statisticService.getProjectPiont(checkId,number);
    }


    /**
     * @Author wenyihan
     * @Description 获取单位问题数量的表格
     * @Date 15:49 2019/8/8
     * @Param checkId String 每个项目的检查ID
     * @Param unit String 包含单位类型和单位名称的二维json数组
     * @Param system String 转为list数组后第x个数据对应problem_collect_detail视图中的preumx+1
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/unitProblemNumStatistic")
    public Object unitProblemNumStatistic(String checkId, String unit, String system){
        return statisticService.unitProblemNumStatistic(checkId, unit, system);
    }

    /**
     * @Author wenyihan
     * @Description 通过checkId、单位类型及其名称获得单位隐患统计表
     * @Date 12:23 2019/8/9
     * @Param [checkId, unit]
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/unitRiskPointStatistic")
    public Object unitRiskPointStatistic(String checkId, String unit){
        return statisticService.unitRiskPiontStatistic(checkId, unit);
    }

    /**
    * 为统计信息获取全部的人员信息
    * @author fanyu
    * @date 2019/8/5 17:17
    * @param ""
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getAllPersonInfoForSta")
    public Object getPersonInfoForSta()
    {
        return statisticService.getPersonInfoForSta();
    }
    /**
    * 根据时间和用户id搜索符合条件的委托方信息
    * @author fanyu
    * @date 2019/10/28 17:55
    * @params [userId, startTime, endTime]
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getClientInfoForUserStatistic")
    public Object getClientInfoForUserStatistic(int userId,String startTime,String endTime)
    {return statisticService.getClientInfoForUserStatistic(userId,startTime,endTime);}

    /**
    * 根据用户id和委托方信息搜索片区信息
    * @author fanyu
    * @date 2019/10/28 18:34
    * @params [userId, startTime, endTime, contractId]
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getTaskForUserStatistic")
    public Object getTaskForUserStatistic(int userId,String startTime,String endTime,String contractId)
    {
        return statisticService.getTaskForUserStatistic(userId,startTime,endTime,contractId);
    }
    /**
    * 根据用户id和片区信息搜索检查项目信息
    * @author fanyu
    * @date 2019/10/29 21:27
    * @params [userId, startTime, endTime, taskId]
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getProjectForUserStatistic")
    public Object getProjectForUserStatistic(int userId,String startTime,String endTime,String taskId)
    {
        return statisticService.getProjectForUserStatistic(userId,startTime,endTime,taskId);
    }
    /**
    * 根据用户id和检查项目id来搜索改检查人员检查的体系内容
    * @author fanyu
    * @date 2019/10/30 14:03
    * @params [userId, startTime, endTime, checkId]
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getSystemInfoForUserStatistic")
    public Object getSystemInfoForUserStatistic(int userId,String startTime,String endTime,String checkId)
    {
        return statisticService.getSystemInfoForUserStatistic(userId,startTime,endTime,checkId);
    }
    /**
    * 获取人员问题统计的表格信息
    * @author fanyu
    * @date 2019/10/30 21:53
    * @params [userId, checkInfo, system]
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getTableDataForUserStatistic")
    public Object getTableDataForUserStatistic(int userId,String checkInfo,String system)
    {
        return statisticService.getTableDataForUserStatistic(userId,checkInfo,system);
    }

    /*根据周期和时间获取项目*/
    @ResponseBody
    @PostMapping("/getProjectByTask")
    public Object getProjectByTask(String taskId,String startTime,String endTime) {
        return statisticService.getProjectByTask(taskId,startTime,endTime);
    }

    /*根据体系和check寻找问题*/
    @ResponseBody
    @PostMapping("/getProblemByCheckandSystem")
    public List<RiskWarning> getProblemByCheckandSystem(String checkId, String system){
        return statisticService.getProblemByCheckandSystem(checkId,system);
    }

    /*根据委托方和单位搜索问题*/
    @ResponseBody
    @PostMapping("/getProblemsByContractandUnit")
    public Object getProblemsByContractandUnit(String contractId,String jsUnit ,String jlUnit,String sgUnit){
        return statisticService.getProblemsByContractandUnit(contractId,jsUnit,jlUnit,sgUnit);
    }

    /*获取所有施工单位*/
    @ResponseBody
    @PostMapping("/getAllsgUnit")
    public Object getAllsgUnit(){
        return statisticService.getAllsgUnit();
    }

    /*获取所有监理单位*/
    @ResponseBody
    @PostMapping("/getAlljlUnit")
    public Object getAlljlUnit(){
        return statisticService.getAlljlUnit();
    }

    /*获取所有施工单位*/
    @ResponseBody
    @PostMapping("/getAlljsUnit")
    public Object getAlljsUnit(){
        return statisticService.getAlljsUnit();
    }
}
